<template>
  <div>
    <el-dialog class="update_dialog" title="更新状态" center :visible.sync="dialogVisible" :before-close="handleClose" :close-on-click-modal='false'>
      <el-form ref="form" :rules="rules" :model="updateForm" label-width="130px">
        <el-form-item label="状态" prop="status">
          <el-select v-model="updateForm.status" placeholder="请选择流程状态" >
            <el-option label="待接单" value="待接单"></el-option>
            <el-option label="代理人撰写中" value="代理人撰写中"></el-option>
            <el-option label="案件内审中" value="案件内审中"></el-option>
            <el-option label="案件修改中" value="案件修改中"></el-option>
            <el-option label="定稿文件发送中" value="定稿文件发送中"></el-option>
            <el-option label="发明人确认定稿中" value="发明人确认定稿中"></el-option>
            <el-option label="上报文件上传中" value="上报文件上传中"></el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button v-no-more-click:3000 type="primary" @click="submitUpdate('form')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dialogVisible: false,
      updateForm: {
        status: '',
      },
      rules: {
        status:[
          { required: true, message: '请输入流程状态', trigger: 'blur' },
        ],
      },
      orderId: null,
    }
  },
  methods: {
    show (data) {
      console.log(data)
      if (data) {
        this.updateForm.status = data.status ? data.status : ''
        this.orderId = data.id
        this.dialogVisible = true
      }
    },
    submitUpdate (formName) {
      this.$refs[formName].validate((valid) => {
        if(valid) {
          this.$axios.put(`api/order/${this.orderId}/update_status`, this.updateForm)
          .then( res => {
            if (res.data.code == 200) {
              this.$message({
                message: '更新成功',
                type: 'success'
              })
              this.dialogVisible = false
              this.$router.go(0)
            } else if (res.data.code == 400) {
              this.$message.error(res.data.message)
            }
          })
          .catch (err => {
            this.$message.error(err)
          })
        }
      })

    },
    handleClose () {
      this.dialogVisible = false
    }
  }
}
</script>

<style lang='less' type='text/css'>

</style>
